package com.bruce.starts.demo.commonerror.logtest;



import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.StopWatch;

import java.util.concurrent.TimeUnit;

/**
 * @author luotuan
 * @Description
 * @create 2021-05-11 16:47
 **/
public class LogDemo {
    private static final Logger log = LoggerFactory.getLogger(LogDemo.class);

    private static String slowString(String s) {
        System.out.println("slowString called via " + s);
        try {
            TimeUnit.SECONDS.sleep(1);
        }
        catch (InterruptedException e) {

        }
        return "ok";
    }

    public static void main(String[] args) {
        StopWatch stopWatch = new StopWatch();
        stopWatch.start("debug1");
        log.debug("debug1:"+slowString("debug1"));
        stopWatch.stop();
        stopWatch.start("debug2");
        log.debug("debug2:{}",slowString("debug2"));
        stopWatch.stop();
        stopWatch.start("debug3");
        if(log.isDebugEnabled()){
            log.debug("debug3:{}",slowString("debug3"));
        }
        stopWatch.stop();
        log.info(stopWatch.prettyPrint());
    }
}
